/*
    $Header: /Windows/Shell/ShellExt.root/ShellExt/src/COvlIcon.cpp 1     08-01-05 0:08 Ken $
    $Log: /Windows/Shell/ShellExt.root/ShellExt/src/COvlIcon.cpp $
 * 
 * 1     08-01-05 0:08 Ken
*/

// ..\Src\COvlIcon.cpp : Implementation of COvlIcon

#include "stdafx.h"

extern HINSTANCE g_hInstance;
#include "COvlIcon.h"

#include "CJunction.h"
#include "Misc.h"


// COvlIcon

HRESULT COvlIcon::IsMemberOf( LPCWSTR pwszPath, DWORD dwAttrib )
{
    DWORD dwAttr=GetFileAttributesW(pwszPath);
    if(FILE_ATTRIBUTE_DIRECTORY&dwAttr)
    {
        TCHAR szTgtPath[MAX_PATH];
        USES_CONVERSION;

        if( (FILE_ATTRIBUTE_REPARSE_POINT&dwAttr)
                && (FALSE!=CJunction::IsJunction(W2T(pwszPath), szTgtPath, ARRAYOF(szTgtPath)))
                && (FALSE!=PathFileExists(szTgtPath)) )
        {
            return S_OK;
        }
    }
    else
    {
        HANDLE hFl=CreateFileW( pwszPath, 0, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_READ,
                                                NULL, OPEN_EXISTING, 0, 0 );
        if(INVALID_HANDLE_VALUE!=hFl)
        {
            BY_HANDLE_FILE_INFORMATION flinfo;
            if( (FALSE!=GetFileInformationByHandle(hFl,&flinfo))
                    &&(1<flinfo.nNumberOfLinks) )    // hard link
            {
                CloseHandle(hFl);
                return S_OK;
            }
            CloseHandle(hFl);
        }
    }

    return E_FAIL;
}

HRESULT COvlIconErr::IsMemberOf( LPCWSTR pwszPath, DWORD dwAttrib )
{
    DWORD dwAttr=GetFileAttributesW(pwszPath);
    if(FILE_ATTRIBUTE_DIRECTORY&dwAttr)
    {
        TCHAR szTgtPath[MAX_PATH];
        USES_CONVERSION;

        if( (FILE_ATTRIBUTE_REPARSE_POINT&dwAttr)
            && (FALSE!=CJunction::IsJunction(W2T(pwszPath), szTgtPath, ARRAYOF(szTgtPath)))
            && (FALSE==PathFileExists(szTgtPath)) )
        {
            return S_OK;
        }
    }

    return E_FAIL;
}
